<script setup>
import { ref } from 'vue'
import adminInfoStore from "@/stores/userInfo.js";
const userInfoStore = adminInfoStore();

const userInfo = ref({
    ...userInfoStore.info
})
const rules = {
    name: [
        { required: true, message: '请输入用户昵称', trigger: 'blur' },
        {
            pattern: /^\S{2,20}$/,
            message: '昵称必须是2-20位的非空字符串',
            trigger: 'blur'
        }
    ],
    phone: [
        {   required: true, message: '请输入手机号码', trigger: 'blur' },
        {   pattern: /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1589]))\d{8}$/,
            message: '请正确填写手机号码',
            trigger: 'blur' 
        }
    ]
}

import { ElMessage } from 'element-plus'
import { adminInfoUpdateService } from '@/api/admin.js'
//修改个人信息
const updateUserInfo = async()=>{
    //调用接口
    let result = await adminInfoUpdateService(userInfo.value);
    ElMessage.success('修改成功');
    //修改pinia中的信息
    userInfoStore.setInfo(userInfo.value)
    
}



</script>
<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>基本资料</span>
            </div>
        </template>
        <el-row>
            <el-col :span="12">
                <el-form :model="userInfo" :rules="rules" label-width="100px" size="large" >
                    <el-form-item label="登录名称">
                        <el-input v-model="userInfo.username" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="用户昵称" prop="name">
                        <el-input v-model="userInfo.name"></el-input>
                    </el-form-item>
                    <el-form-item label="手机号码" prop="phone">
                        <el-input v-model="userInfo.phone"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="updateUserInfo" >提交修改</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </el-card>
</template>